import Flutter
import UIKit


public class SwiftLinphoneFlutterPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "linphone_flutter", binaryMessenger: registrar.messenger())
    let instance = SwiftLinphoneFlutterPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
    LinphoneUtil.Instance.start(registrar: registrar)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

      if(call.method=="getPlatformVersion"){
          result("iOS " + UIDevice.current.systemVersion)
      } else if(call.method=="getLinphoneVersion"){
         result(LinphoneUtil.Instance.getVersion())
      } else if(call.method=="login"){
          LinphoneUtil.Instance.login(call: call, result: result)
      } else if (call.method=="unregister") {
          LinphoneUtil.Instance.unregister()
      } else if (call.method=="delete") {
          LinphoneUtil.Instance.delete()
      } else if (call.method=="terminate") {
          LinphoneUtil.Instance.terminateCall()
      } else if (call.method=="accept") {
          LinphoneUtil.Instance.acceptCall()
      } else if (call.method=="outgoingCall") {
          LinphoneUtil.Instance.outgoingCall(call:call)
      } else if (call.method=="hangUp") {
          LinphoneUtil.Instance.hangUp()
      } else if (call.method=="transferTo") {
          LinphoneUtil.Instance.transferTo(call: call)
      } else if (call.method=="pauseOrResume") {
          LinphoneUtil.Instance.pauseOrResume()
      } else if (call.method=="micEnabled") {
          LinphoneUtil.Instance.muteMicrophone(result: result)
      } else if (call.method=="toggleSpeaker") {
          LinphoneUtil.Instance.toggleSpeaker(result: result)
      } else if (call.method=="remoteAddressUri") {
          LinphoneUtil.Instance.remoteAddressUri(result: result)
      }  else {
        result(FlutterMethodNotImplemented);
      }
      
  }
}
